﻿using SQLite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teriri.File.Server.Entity;
using Teriri.File.Server.Filter;
using TouchSocket.Core;
using TouchSocket.Dmtp.Rpc;
using TouchSocket.Rpc;

namespace Teriri.File.Server.Service
{
    [ServiceFilterAttribute]
    public class LogService : RpcServer
    {
        [Description("获取解压日志")]
        [DmtpRpc("Log_DecompressingLog")]
        public PagedList<DecompressingFileLogEntity> DecompressingLog(int page, int limit)
        {
            using (var connection = new SQLiteConnection("log.db"))
            {
                var query = connection.Table<DecompressingFileLogEntity>();
                var count = query.Count();
                var data = query.OrderByDescending(a => a.StartTime).Skip((page - 1) * limit).Take(limit).ToList();
                var totalPages = (int)Math.Ceiling(count / (double)limit);

                var res = new PagedList<DecompressingFileLogEntity>()
                {
                    Items = data,
                    TotalCount = count,
                    TotalPages = totalPages,
                };

                return res;
            }
        }
    }
}
